fix(posthog): add rewrites for posthog reverse proxy routes unconditionally, remove unused POSTHOG_ENABLED envvar#1548
Merged
waleedlatif1 merged 1 commit intostagingfrom Oct 6, 2025
Merged
Conversation
…onally, remove unused POSTHOG_ENABLED envvar
Contributor
There was a problem hiding this comment.
Greptile Overview
Summary
This PR fixes PostHog analytics integration by simplifying the configuration approach. The changes remove the conditional logic that previously controlled when PostHog reverse proxy routes were available, making them always accessible regardless of environment configuration.The key changes involve two files:
- next.config.ts: The
rewrites()function now unconditionally returns PostHog proxy routes (/ingest/static/:path*and/ingest/:path*) that forward requests to PostHog's US assets and API endpoints. Previously, these routes were only added whenPOSTHOG_ENABLEDwas truthy. - lib/env.ts: Removes the unused server-side
POSTHOG_ENABLEDenvironment variable from the Zod schema validation, while keeping the client-side PostHog variables (NEXT_PUBLIC_POSTHOG_ENABLEDandNEXT_PUBLIC_POSTHOG_KEY) intact.
This approach aligns with best practices for analytics integration where reverse proxy routes should always be available to avoid CORS issues and ad blocker interference. PostHog functionality is now controlled entirely through client-side environment variables, which is more appropriate since PostHog is primarily a client-side analytics service. The reverse proxy setup ensures reliable communication with PostHog's servers by routing requests through the application's domain rather than making direct cross-origin requests.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| apps/sim/next.config.ts | 5/5 | Simplified PostHog rewrites to be always available, removing conditional logic |
| apps/sim/lib/env.ts | 4/5 | Removed unused server-side POSTHOG_ENABLED environment variable from schema |
Confidence score: 5/5
- This PR is safe to merge with minimal risk as it simplifies configuration and removes unused code
- Score reflects straightforward changes that improve reliability by removing conditional complexity
- No files require special attention as both changes are clean removals of unnecessary conditional logic
Sequence Diagram
sequenceDiagram
participant User
participant App as "Next.js App"
participant PostHog as "PostHog Analytics"
User->>App: "Visit app page"
App->>App: "Load Next.js config"
App->>App: "Apply rewrites unconditionally"
Note over App: "Rewrites now added without POSTHOG_ENABLED check"
User->>App: "Request /ingest/static/:path*"
App->>PostHog: "Proxy to https://us-assets.i.posthog.com/static/:path*"
PostHog->>App: "Return static assets"
App->>User: "Return proxied assets"
User->>App: "Request /ingest/:path*"
App->>PostHog: "Proxy to https://us.i.posthog.com/:path*"
PostHog->>App: "Return analytics data"
App->>User: "Return proxied response"
Note over App: "POSTHOG_ENABLED env var removed from env.ts"
Note over App: "Rewrites always active for reverse proxy"
2 files reviewed, no comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
add rewrites for posthog reverse proxy routes unconditionally, remove unused POSTHOG_ENABLED envvar
Type of Change
Testing
Tested manually.
Checklist